package com.study.base.io.nio.demo.block;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * Created by tan on 2017/7/17.
 */
public class NIOServer {
	private ServerSocketChannel serverSocketChannel;

	public NIOServer(int port) throws IOException {
		//创建ServerSocketChannel
		serverSocketChannel = ServerSocketChannel.open();
		//ServerSocketChannel绑定端口
		//这两种方式有什么区别?
		//serverSocketChannel.socket().bind(new InetSocketAddress(port));
		serverSocketChannel.bind(new InetSocketAddress(port));
	}

	public void start() throws IOException {
		while (true) {
			SocketChannel channel = serverSocketChannel.accept();
		}
	}
}
